<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
</head>
<title>每日必赚记录分页</title>
<style>.layui-table-cell{
        height:auto !important;
    }</style>
<div class="lay-box">
    <form class="layui-form" action="" style="margin-top: 10px">
        <div class="layui-inline" style="margin: 0 0 8px 20px;">
            <label class="layui-form-label" style="width: 95px">起始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="star" placeholder="请选择时间">
            </div>
        </div>
        <div class="layui-inline" style="margin: 0 0 8px 20px;">
            <label class="layui-form-label" style="width: 95px">结束时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="end" placeholder="请选择时间">
            </div>
        </div>
        <div style="width: 180px;display: inline-block;margin: 0 0 8px 20px;">
            <input type="text" name="member_id" id="member_id" required lay-verify="required" placeholder="请输入用户id"
                   autocomplete="off"
                   class="layui-input">
        </div>
        <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
            <select name="status" id="status" lay-verify="" style="width: 300px">
                <option value="">选择任务状态</option>
                <option value="1">任务成功</option>
                <option value="0">待提交</option>
                <option value="-1">用户主动放弃</option>
                <option value="-3">系统释放</option>
            </select>
        </div>
        <div style="width: 180px;display: inline-block;margin: 0 0 8px 20px;">
            <input type="text" name="appStore" id="appStore" required lay-verify="required" placeholder="请输入渠道"
                   autocomplete="off"
                   class="layui-input">
        </div>
        <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
            <select name="type" id="type" lay-verify="" style="width:300px">
                <option value="">选择任务类型</option>
                <option value="1">下载</option>
                <option value="0">浏览</option>
            </select>
        </div>

        <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
            <select name="sdk_key" id="sdk_key" lay-verify="" style="width:300px">
                <option value="">选择数据源</option>
                <#list item as list>
                    <option value="${list.sdkKey}">${list.taskName}</option>
                </#list>

            </select>
        </div>

        <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
            <select name="down_type" id="down_type" lay-verify="" style="width:300px">
                <option value="">选择任务下载类型</option>
                <option value="1">普通下载</option>
                <option value="0">应用商店下载</option>
            </select>
        </div>
        <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
            <select name="is_new_member" id="is_new_member" lay-verify="" style="width:300px">
                <option value="">新老用户筛选</option>
                <option value="1">新用户</option>
                <option value="0">老用户</option>
            </select>
        </div>
    </form>
<#--    <button class="layui-btn" onclick="gradeEdit()">-->
<#--        <i class="layui-icon">&#xe608;</i> 添加-->
<#--    </button>-->
    <span onclick="search()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">查询</span>
    <span onclick="selectAlldata()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">统计</span>
    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>

<style>
    .lay-box {
        padding: 8px 12px;
    }

    .layui-form-checkbox[lay-skin=primary] i {
        top: 5px;
    }
</style>
<#--<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="save">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>-->


<!--请在下方写此页面业务相关的脚本-->
<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{
           d.enable== 1 ? 'checked' : '' }}>
</script>

<script type="text/javascript">
    var appStore = "";
    var status = "";
    var type = "";
    var member_id = "";
    var sdk_key = "";
    var startDate = "";
    var endDate = "";
    var searchKey = "";
    var tableIns;
    var ids = "";
    var isNewMember = "";
    var form;
    var table = "tb_download_member_record";
    layui.use('table', function () {
        tableIns = layui.table,
            form = layui.form;
        form.render();
        tableIns.render({
            elem: '#layTable'
            ,
            url: '/sys/downloadmemberrecord/data'
            ,
            method: 'POST'
            ,

            where: {
                start: startDate,
                end: endDate,
                <#if pkgName??>'pkgName': '${pkgName}',</#if>
                memberId:member_id,
                sdkKey: sdk_key,
                status: status,
                type: type,
                appStore: appStore,
                downType:""
            }
            ,
            id: 'dataTableId'
            ,
            toolbar:true,
            cols: [[
            {
                    field: 'gmt_created', title: '创建时间/放弃时间/领奖时间', templet: function (data) {
                        return '<p>'+localDateTimeFormat(data.createTime)+'</p>'+
                            '<p>'+localDateTimeFormat(data.releaseTime)+'</p>'+
                            '<p>'+localDateTimeFormat(data.pushTime)+'</p>';
                    }, align: 'center', width: 200, sort: true
                }
                , {
                    field: 'appName',
                    title: 'app名称',
                    width: 150,
                    align: 'center',
                    sort: true, templet: function (data) {
                        return data.appName;
                    }
                }, {
                    field: 'type',
                    title: '任务类型0下载1浏览',
                    width: 150,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        if (data.type === 1) {
                            return '下载';
                        } else {
                            return '浏览';
                        }
                    }
                }, {
                    field: 'status',
                    title: '任务状态',
                    width: 150,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        if (data.status === 1) {
                            return '任务成功';
                        } else if (data.status === -1) {
                            return '用户放弃任务';
                        } else if (data.status === -3){
                            return '系统释放';
                        }else {
                            return '待提交';
                        }
                    }
                }, {
                    field: 'isOpen',
                    title: '是否激活',
                    width: 150,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        if (data.isOpen === 1) {
                            return '激活成功';
                        } else  {
                            return '未激活';
                        }
                    }
                }, {
                    field: 'money',
                    title: '奖励',
                    width: 150,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        if (data.rewardType === 1) {
                            return data.money / 100 + '元';
                        } else {
                            return data.money + '金币';
                        }
                    }
                }, {
                    field: 'sdkKey',
                    title: '任务数据源key',
                    width: 150,
                    align: 'center',
                    sort: true
                }, {
                    field: 'downType',
                    title: '下载类型',
                    width: 150,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        if (data.downType === 0) {
                            return  '应用商店下载';
                        } else {
                            return '普通下载';
                        }
                    }
                }
                , {
                    field: 'appStore',
                    title: '渠道',
                    width: 150,
                    align: 'center',
                    sort: true
                }

                , {
                    field: 'pkgName',
                    title: '包名',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'memberId',
                    title: '用户id',
                    width: 150,
                    align: 'center',
                    sort: true
                }

                , {
                    field: 'time',
                    title: '体验秒数',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'endTime',
                    title: '下载完成时间',
                    width: 150,
                    align: 'center',
                    sort: true, templet: function (data) {
                        return '<p>'+localDateTimeFormat(data.endTime)+'</p>';
                    }
                }


                , {
                    field: 'ua',
                    title: '手机参数ua',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'imei',
                    title: 'imei',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'ipAddress',
                    title: 'ip地址',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'appStore',
                    title: '渠道',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'orderId',
                    title: '商户订单号',
                    width: 150,
                    align: 'center',
                    sort: true
                }


                // , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150, align: 'center'}

            ]]
            ,
            page: true
        });

        form.on('switch(sexDemo)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, 1);
            } else {
                commonenable(this.value, 0);
            }

        });
        tableIns.on('checkbox(tableFilter)', function (obj) {
            var checkStatus = tableIns.checkStatus('dataTableId');
            var dataList = checkStatus.data;
            if (dataList != null && dataList.length > 0) {

                for (var i = 0; i < dataList.length; i++) {
                    ids += dataList[i].id + ",";
                }
            }
        });

        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/delete/data",
                    type: 'post',
                    data: {"table": table, "ids": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            search();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    deleteId(data.id)
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer_show("修改", "/sys/downloadmemberrecord/edit?id=" + data.id, "650", "650");
                parent.search();
            }
        });
    });
    layui.use('form', function () {
        var form = layui.form;
        form.render();
        //监听提交
        form.on('submit(formDemo)', function (data) {
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    function selectAlldata() {
        appStore = $("#appStore").val();
        startDate = $("#star").val();
        endDate = $("#end").val();
        window_show("统计", "/downloadmemberrecord/periodtable?star="+startDate+"&end="+endDate+"&appStore="+appStore, "1000", "1000");
    }
    function search() {
        appStore = $("#appStore").val();
        startDate = $("#star").val();
        endDate = $("#end").val();
        member_id = $("#member_id").val();
        type = $("#type").val();
        sdk_key = $("#sdk_key").val();
        status = $("#status").val();
      var  down_type = $("#down_type").val();
        isNewMember = $("#is_new_member").val();

        tableIns.reload('dataTableId', {
            where: {
                start: startDate,
                end: endDate,
                memberId:member_id,
                sdkKey: sdk_key,
                status: status,
                type: type,
                appStore: appStore,
                downType:down_type,
                isNewMember:isNewMember

            }
            , page: {
                curr:1
            }
        });
    }


    function gradeEdit() {
        layer_show("新增", "/sys/downloadmemberrecord/add", "650", "600");
    }

    function showmsg(msg) {
        layer.msg(msg)
    }

    function commonenable(id, status) {
        $.ajax({
            url: "/common/commonSwitch",
            type: 'post',
            data: {"table": table, "id": id, "status": status, "feild": "has_deleted"},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#star'
            , type: 'datetime'

        });
        laydate.render({
            elem: '#end'
            , type: 'datetime'

        });
    });


    function localDateTimeFormat(value){
        var arr = value;
        if(arr==null || arr==""){
            return "-";
        }else{
            for(var i = 0; i < arr.length; i++){
                if(arr[i].length == 1){
                    arr[i] = "0" + arr[i];
                }
            }
            if(arr.length == 5){
                var getFormatTime = arr[0] + "-" + arr[1] + "-" + arr[2] + "\t" + arr[3] + ":" + arr[4] + ":" + "00";
            }else{
                var getFormatTime = arr[0] + "-" + arr[1] + "-" + arr[2] + "\t" + arr[3] + ":" + arr[4] + ":" + arr[5];
            }

            return getFormatTime;
        }

    }

</script>
<!--/请在上方写此页面业务相关的脚本-->
